<?php
/*
 *
 *
 */
function get_record_amount($type='',$table=''){
    if($type == "users_add_today"){
        $map['reg_time']   = array('between',array());
    }else if($type == "order_add_today"){
        $map['add_time']   = array('between',array());
    }else if($type == "visit_users_today"){
        $map['visit_time'] = array('between',array());
    }else if($type == "online_users"){
        $map['is_online']  = 1;
    }else if($type == "shipping_order"){
        $map['shipping_stat'] = 0;
    }else if($type == "not_confirmed_order"){
        $map['business_confirmation'] = 0;
    }else if($type == "pay_order"){
        $map['pay_stat'] = 0;
    }else if($type == "done_order"){
        $map['order_stat'] = 1;
    }else if($type == "out_of_stock"){
        $map['add_time']   = array('between',array());
    }else if($type == "back_order"){
        $map['add_time']   = array('between',array());
    }else if($type == "part"){
        $map['add_time']   = array('between',array());
    }else if($type == "total_goods"){
        $map = array();
    }else if($type == "warning_goods"){
        $map['warning_number'] = 'goods_number';
    }else if($type == "best_goods"){
        $map['is_best'] = 1;
    }else if($type == "new_goods"){
        $map['is_new'] = 1;
    }else if($type == "hot_goods"){
        $map['is_hot'] = 1;
    }else if($type == "promotion_goods"){
        $map['is_promotion'] = 1;
    }

    return M($table)->where($map)->count();
}
/*
 *
 *
 */
function get_home_array($config_name=''){
    $config = C($config_name);
    foreach($config as $key=>$val){
        $condition = explode(',',$val['amount']);
        $config[$key]['amount'] = get_record_amount($condition[0],$condition[1]);
        if(empty($val['url'][1])){
            $config[$key]['url']    = U($val['url'][0]);
        }else{
            $config[$key]['url']    = U($val['url'][0],array('stat'=>$val['url'][1]));
        }
    }

    return $config;
}
/*
 *
 *
 */
function get_children_menu($parent_id=''){
    $menu_list = C('menu');
    $parent_id = substr($parent_id,1,1);
    foreach($menu_list as $val){
        if($val['top'] == $parent_id){
            $children_menu[] = $val;
        }
    }
    $html = '';
    foreach($children_menu as $val){
        $html .= '<li><a href="'.U($val['url']).'" target="home_frame"><span class="'.$val['icon'].'"></span>  '.$val['name'].'</a></li>';
    }

    return $html;
}

/*
 *  商品详情页面-生成会员价格表单
 *
 */
function get_user_price_field($goods_id=0){
    $map['goods_id'] = $goods_id;
    $goods_info = M('goods')->field('user_rank,discount_price')->where($map)->find();
    $form = '';
    if(empty( $goods_info)){
        $user_rank = M('user_rank')->select();
        foreach($user_rank as $key=>$val){
            $form .= '<span class="am-text-xs">'.$val['rank_name'].'</span>'.
                '<input type="text" name="user_price[]" style="display:inline-block;width:70%;margin-left:10px;"/>';
        }
    }else{

    }

    return $form;
}

/*
 *  商品详情页-生成优惠价格表单
 *
 */
function get_discount_price_field($goods_id=0){
    $map['goods_id'] = $goods_id;
    $goods_info = M('goods')->field('discount_amount,discount_price')->where($map)->find();
    if(empty($goods_info)){
        $form  = '<a href="javascript:;" onclick="add_price_input(this)">[+]</a>'.'<span class="am-text-xs">优惠数量</span>';
        $form .= '<input type="text" name="discount_amount[]" class="discount_amount" style="display:inline-block;width:30%;margin:0 10px;"/>';
        $form .= '<span class="am-text-xs">优惠价格</span>';
        $form .= '<input type="text" name="discount_price[]" class="discount_price" style="display:inline-block;width:30%;margin-left:10px;"/>';
    }else{

    }

    return $form;
}

function get_goods_info($goods_id=0,$attr_name=''){
    if(empty($goods_id)){
        switch($attr_name){
            case 'shop_price':echo 0;break;
            case 'market_price':echo 0;break;
            case 'warning_number':echo 1;break;
            case 'goods_number':echo 1;break;
        }
    }else{
        $map['goods_id'] = $goods_id;
        return M('goods_info')->field($attr_name)->where($map)->find();
    }
}
